home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 4 / Meeting Pearls Vol. IV (1996)(GTI - Schatztruhe)[!].iso / Pearls / libs / bgui / Demos / MultiFont.c < prev    next >
C/C++ Source or Header  |  1995-08-17  |  5KB  |  178 lines

  1. ;/*
  2. dcc multifont.c -mi -ms -mRR -proto -lbgui
  3. quit
  4. */
  5. /*
  6.  *    MULTIFONT.C
  7.  *
  8.  *    (C) Copyright 1995 Jaba Development.
  9.  *    (C) Copyright 1995 Jan van den Baard.
  10.  *        All Rights Reserved.
  11.  */
  12.  
  13. #include "democode.h"
  14.  
  15. /*
  16.  *    Fonts used in the code.
  17.  */
  18. struct TextAttr ButtonFont    = { "diamond.font", 12, FS_NORMAL, FPF_DISKFONT };
  19. struct TextAttr Info1Font    = { "emerald.font", 17, FS_NORMAL, FPF_DISKFONT };
  20. struct TextAttr Info2Font    = { "opal.font",    9,  FS_NORMAL, FPF_DISKFONT };
  21.  
  22. struct TextFont *Button, *Info1, *Info2;
  23. struct Library    *DiskfontBase;
  24.  
  25. /*
  26.  *    Object ID's
  27.  */
  28. #define ID_QUIT                 1
  29.  
  30. /*
  31.  *    Info texts.
  32.  */
  33. UBYTE  *IText1 = ISEQ_C ISEQ_HIGHLIGHT "MultiFont";
  34. UBYTE  *IText2 = ISEQ_C "This demo shows you how you\n"
  35.          "can use different fonts inside a\n"
  36.          "single window.";
  37.  
  38. VOID StartDemo( void )
  39. {
  40.     struct Window        *window;
  41.     Object            *WO_Window, *GO_Quit;
  42.     ULONG             signal, rc;
  43.     BOOL             running = TRUE;
  44.  
  45.     /*
  46.      *    We need this one to open the fonts.
  47.      */
  48.     if ( DiskfontBase = OpenLibrary( "diskfont.library", 36 )) {
  49.         /*
  50.          *    We open the fonts ourselves since BGUI
  51.          *    opens all fonts with OpenFont() which
  52.          *    means that they have to be resident
  53.          *    in memory.
  54.          */
  55.         if ( Button = OpenDiskFont( &ButtonFont )) {
  56.             if ( Info1 = OpenDiskFont( &Info1Font )) {
  57.                 if ( Info2 = OpenDiskFont( &Info2Font )) {
  58.                     /*
  59.                      *    Create the window object.
  60.                      */
  61.                     WO_Window = WindowObject,
  62.                         WINDOW_Title,        "Multi-Font Demo",
  63.                         WINDOW_AutoAspect,    TRUE,
  64.                         WINDOW_LockHeight,    TRUE,
  65.                         WINDOW_RMBTrap,         TRUE,
  66.                         WINDOW_MasterGroup,
  67.                             VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  68.                                 StartMember,
  69.                                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 2 ),
  70.                                         FRM_Type,        FRTYPE_BUTTON,
  71.                                         FRM_Recessed,        TRUE,
  72.                                         StartMember,
  73.                                             InfoObject,
  74.                                                 INFO_TextFormat,    IText1,
  75.                                                 INFO_HorizOffset,    0,
  76.                                                 INFO_VertOffset,    0,
  77.                                                 INFO_FixTextWidth,    TRUE,
  78.                                                 INFO_MinLines,        1,
  79.                                                 BT_TextAttr,        &Info1Font,
  80.                                             EndObject,
  81.                                         EndMember,
  82.                                         StartMember,
  83.                                             HorizSeparator,
  84.                                         EndMember,
  85.                                         StartMember,
  86.                                             InfoObject,
  87.                                                 INFO_TextFormat,    IText2,
  88.                                                 INFO_HorizOffset,    0,
  89.                                                 INFO_VertOffset,    0,
  90.                                                 INFO_FixTextWidth,    TRUE,
  91.                                                 INFO_MinLines,        3,
  92.                                                 BT_TextAttr,        &Info2Font,
  93.                                             EndObject,
  94.                                         EndMember,
  95.                                     EndObject,
  96.                                 EndMember,
  97.                                 StartMember,
  98.                                     HGroupObject,
  99.                                         VarSpace( 50 ),
  100.                                         StartMember,
  101.                                             GO_Quit = ButtonObject,
  102.                                                 LAB_Label,    "_Quit",
  103.                                                 LAB_Underscore, '_',
  104.                                                 ButtonFrame,
  105.                                                 GA_ID,        ID_QUIT,
  106.                                                 BT_TextAttr,    &ButtonFont,
  107.                                             EndObject,
  108.                                         EndMember,
  109.                                         VarSpace( 50 ),
  110.                                     EndObject, FixMinHeight,
  111.                                 EndMember,
  112.                             EndObject,
  113.                     EndObject;
  114.  
  115.                     /*
  116.                      *    Object created OK?
  117.                      */
  118.                     if ( WO_Window ) {
  119.                         /*
  120.                          *    Assign the key to the button.
  121.                          */
  122.                         if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  123.                             /*
  124.                              *    try to open the window.
  125.                              */
  126.                             if ( window = WindowOpen( WO_Window )) {
  127.                                 /*
  128.                                  *    Obtain it's wait mask.
  129.                                  */
  130.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  131.                                 /*
  132.                                  *    Event loop...
  133.                                  */
  134.                                 do {
  135.                                     Wait( signal );
  136.                                     /*
  137.                                      *    Handle events.
  138.                                      */
  139.                                     while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  140.                                         /*
  141.                                          *    Evaluate return code.
  142.                                          */
  143.                                         switch ( rc ) {
  144.  
  145.                                             case    WMHI_CLOSEWINDOW:
  146.                                             case    ID_QUIT:
  147.                                                 running = FALSE;
  148.                                                 break;
  149.                                         }
  150.                                     }
  151.                                 } while ( running );
  152.                             } else
  153.                                 Tell( "Could not open the window\n" );
  154.                         } else
  155.                             Tell( "Could not assign gadget keys\n" );
  156.                         /*
  157.                          *    Disposing of the window object will
  158.                          *    also close the window if it is
  159.                          *    already opened and it will dispose of
  160.                          *    all objects attached to it.
  161.                          */
  162.                         DisposeObject( WO_Window );
  163.                     } else
  164.                         Tell( "Could not create the window object\n" );
  165.                     CloseFont( Info2 );
  166.                 } else
  167.                     Tell( "Could not open opal.font\n" );
  168.                 CloseFont( Info1 );
  169.             } else
  170.                 Tell( "Could not open emerald.font\n" );
  171.             CloseFont( Button );
  172.         } else
  173.             Tell( "Could not open diamond.font\n" );
  174.         CloseLibrary( DiskfontBase );
  175.     } else
  176.         Tell( "Could not open diskfont.library\n" );
  177. }
  178.